import javax.swing.JFrame;  
import java.awt.event.MouseAdapter;  
import java.awt.event.MouseEvent;  
import java.awt.Color;
import java.awt.Graphics;


public class figures extends JFrame{
    
    public Board board = new Board();
    
	public static void main(String args[]) {
		figures demo = new figures();  
	}



	public figures() {
		setSize(800, 800);
		
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		MouseEventhandlers mC = new MouseEventhandlers(this); //create respons to mouse
		this.addMouseListener(mC);  //Listener for the mouse
		this.addMouseMotionListener(mC); //Listener for mouse movement

		setVisible(true);
		
	}

	public void paint(Graphics g) {
   

        //We paint the board
        g.setColor(new Color(50,205,50));
        g.fillRect(120,120,320,320);

        g.setColor(Color.BLACK);
        g.drawRect(120,120,320,320);
        //horisontiellt
        g.drawLine(120,160,440,160);
        g.drawLine(120,200,440,200);  
        g.drawLine(120,240,440,240);  
        g.drawLine(120,280,440,280);
        g.drawLine(120,320,440,320);
        g.drawLine(120,360,440,360);
        g.drawLine(120,400,440,400);
        g.drawLine(120,440,440,440);


            //Lodraett
        g.drawLine(160,120,160,440);
        g.drawLine(200,120,200,440);  
        g.drawLine(240,120,240,440);  
        g.drawLine(280,120,280,440);
        g.drawLine(320,120,320,440);
        g.drawLine(360,120,360,440);
        g.drawLine(400,120,400,440);
        g.drawLine(440,120,440,440);

    
		for(int i=0;i<8;i++){     
		     for(int j=0;j<8;j++){
		        if(board.thisBoard[i][j]=='B'){
		            
		            //Painting the black figure
		            g.setColor(Color.BLACK);
		            g.fillOval((i*40+125),(j*40+125), 30, 30); 
		
		            
		
		    
		        }
		        if(board.thisBoard[i][j]=='W'){
		            //Painting the white figure
		            g.setColor(Color.WHITE);
		            g.fillOval((i*40+125),(j*40+125), 30, 30); 
		        }
		    
		    }
		}
	}
}

class MouseEventhandlers extends MouseAdapter{
private figures demo;
	public MouseEventhandlers(figures demo){
		this.demo = demo;
	}


	public void mousePressed(MouseEvent e){
	
		Coordinate move = new Coordinate((e.getX()-125)/40, (e.getY()-125)/40);
	    demo.board.makeMove(move, demo.board.plays);

	    demo.board.showboard();
	    demo.repaint();
	}

}